import turtle

# 创建一个窗口和画笔
screen = turtle.Screen()
screen.bgcolor("white")

pen = turtle.Turtle()
pen.speed(0)

# 科赫雪花递归函数
def koch_curve(length, depth):
    if depth == 0:
        pen.forward(length)
    else:
        length /= 3.0
        koch_curve(length, depth-1)
        pen.left(60)
        koch_curve(length, depth-1)
        pen.right(120)
        koch_curve(length, depth-1)
        pen.left(60)
        koch_curve(length, depth-1)

# 绘制科赫雪花
def draw_snowflake(length, depth):
    for _ in range(3):
        koch_curve(length, depth)
        pen.right(120)

# 设置初始位置
pen.penup()
pen.goto(-150, 100)
pen.pendown()

# 绘制雪花
draw_snowflake(300, 4)

# 点击关闭窗口
screen.exitonclick()